public class Solution12 {
    public String intToRoman(int num) {
        StringBuilder stringBuilder=new StringBuilder();
        int n1=num/1000;
        for (int i=0;i<n1;i++){
            stringBuilder.append('M');
        }
        num=num%1000;
        n1=num/100;
        if (n1==4){
            stringBuilder.append("CD");
        }else if (n1==9){
            stringBuilder.append("CM");
        }else if (n1>=5){
            stringBuilder.append('D');
            for (int i=6;i<=n1;i++){
                stringBuilder.append('C');
            }
        }else{
            for (int i=1;i<=n1;i++){
                stringBuilder.append('C');
            }
        }
        num=num%100;
        n1=num/10;
        if (n1==4){
            stringBuilder.append("XL");
        }else if (n1==9){
            stringBuilder.append("XC");
        }else if (n1>=5){
            stringBuilder.append('L');
            for (int i=6;i<=n1;i++){
                stringBuilder.append('X');
            }
        }else{
            for (int i=1;i<=n1;i++){
                stringBuilder.append('X');
            }
        }
        num=num%10;
        n1=num;
        if (n1==4){
            stringBuilder.append("IV");
        }else if (n1==9){
            stringBuilder.append("IX");
        }else if (n1>=5){
            stringBuilder.append('V');
            for (int i=6;i<=n1;i++){
                stringBuilder.append('I');
            }
        }else{
            for (int i=1;i<=n1;i++){
                stringBuilder.append('I');
            }
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution12().intToRoman(1994));
    }
}
